package com.shenmazong.serveruserapi.controller;

import com.shenmazong.serveruserapi.service.UserService;
import com.shenmazong.serveruserapi.util.ConstUtil;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;
import java.util.HashMap;

@RestController
public class UserController {

    @Autowired
    private UserService userService;

    // https://market.console.aliyun.com/imageconsole/index.htm?spm=5176.6660585.774526198.1.6f1f6bf8OfhM4A#/bizlist?_k=d6smlb
    // https://market.aliyun.com/products/57002003/cmapi00037891.html?spm=5176.2020520132.101.2.e9cd7218EgZ91o#sku=yuncode3189100001

    /**
     * TODO sendSMS 发送手机验证码
     * @param mobile
     * @return
     */
    @PostMapping(value = "/sendSMS")
    public Object sendSMS(@RequestParam("mobile") String mobile) {
        return userService.sendSMS(mobile);
    }

    /**
     * TODO verifyCode 验证验证码
     * @param mobile
     * @param code
     * @return
     */
    @PostMapping(value = "/verifyCode")
    public Object verifyCode(@RequestParam("mobile") String mobile,
                             @RequestParam("code") String code) {
        return userService.verifyCode(mobile, code);
    }

    /**
     * TODO quitLogin 快捷登陆
     * @param userId
     * @param oldToken
     * @return
     */
    @PostMapping(value = "/quitLogin")
    public Object quickLogin(@RequestParam("userId") Integer userId,
                             @RequestParam("oldToken") String oldToken) {


        HashMap<String, Object> resultMap = new HashMap<>();
        resultMap.put("code", 0);
        resultMap.put("userId", 111);
        //resultMap.put("token", token);

        return resultMap;
    }

    /**
     * TODO uploadHead 头像上传
     * @param file
     * @return
     */
    @PostMapping(value = "/uploadHead")
    public Object uploadHead(@RequestParam("uploadFile") MultipartFile file,
                             @RequestParam("userId") Integer userId) {
        return null;
    }



}
